package com.innovation.service;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import com.innovation.cache.PlayerCache;
import com.innovation.config.ConfigHelper;
import com.innovation.constants.CommonConstant;
import com.innovation.dao.PlayerDao;
import com.innovation.data.model.ModelData;
import com.innovation.data.model.Player;
import com.innovation.exception.PatException;
import com.innovation.message.ErrorCodeProto.ErrorCode;
import com.innovation.message.ErrorMsgProto.ErrorMsg;
import com.innovation.message.PBMessageProto.PBMessage;
import com.innovation.util.MessageUtil;
import com.innovation.util.NettyUtil;
import com.innovation.util.TimeUtil;

public class PlayerService {
	
	/**
	 * 登录日志
	 */
	private static Logger loginLog = Logger.getLogger("LOGIN");
	private static Logger logger = Logger.getLogger(PlayerService.class);
	
	private static PlayerDao playerDao = new PlayerDao();
//	private static PlayerDailyDataDao dailyDataDao = new PlayerDailyDataDao();
	
	/**
	 * 通过id从DB加载玩家基本数据
	 * @param id
	 * @return
	 */
	public static Player loadPlayerById(int id) {
		return playerDao.getPlayer(id);
	}

	/**
	 * 通过openId从DB加载玩家基本数据
	 * @param openId
	 * @return
	 */
	public static Player loadPlayerByOpenId(String openId) {
		Player player = playerDao.getPlayer(openId);
		return player;
	}
	
	/**
	 * 保存玩家数据到DB中
	 * @param player
	 */
	public static void savePlayer(Player player) {
		playerDao.save(player);
	}
	
	/**
	 * 加载玩家数据
	 * 
	 * @param player
	 * @param data
	 */
	public static void loadPlayerDataFromDB(Player player, int data) {
		if (player != null) {
			synchronized (player) {
				if(player.checkDataLoad(data)){
					return;
				}
				long startTime = System.currentTimeMillis();
//				//玩家英雄数据
//				if((data & ModelData.DATA_HERO) == ModelData.DATA_HERO){
//					HeroService.loadPlayerHero(player);
//				}
//				//玩家道具数据
//				if((data & ModelData.DATA_ITEM) == ModelData.DATA_ITEM){
//					ItemService.loadPlayerItem(player);
//				}
//				//玩家PVE数据
//				if((data & ModelData.DATA_PVE) == ModelData.DATA_PVE){
//					PVEService.loadPlayerPVE(player);
//				}
//				//玩家每日重置数据
//				if((data & ModelData.DATA_DAILY_DATA) == ModelData.DATA_DAILY_DATA){
//					PlayerService.loadPlayerDailyData(player);
//				}
//				//玩家任务数据
//				if((data & ModelData.DATA_MISSION) == ModelData.DATA_MISSION){
//					PlayerMissionService.loadPlayerMission(player);
//				}
//				//玩家消息数据
//				if((data & ModelData.DATA_MSG) == ModelData.DATA_MSG){
//					MessageService.loadPlayerMessage(player);
//				}
				player.addDataLoadSign(data);
				logger.info("load data from db playerId="+ player.getId()+" useTime="+(System.currentTimeMillis() - startTime)+" type="+data);
			}
		}
	}
	

//	/**
//	 * 从数据库加载每日重置数据
//	 * @param player
//	 */
//	private static void loadPlayerDailyData(Player player) {
//		PlayerDailyData playerDailyData = dailyDataDao.getPlayerDailyData(player.getId());
//		player.setPlayerDailyData(playerDailyData);
//	}
	
//	/**
//	 * 重置玩家每日
//	 * @param player
//	 */
//	public static void resetPlayerDailyData(Player player){
//		PlayerDailyData dailyData = player.getPlayerDailyData();
//		if(dailyData == null){
//			return;
//		}
//		if(!TimeUtil.isToday(dailyData.getResetTime())){
//			dailyData.setResetTime(TimeUtil.now());
//			dailyData.setHeroLotteryTimes(1);//免费扭蛋次数置为1
//			dailyDataDao.save(dailyData);
//			
//			//重置每日任务
//			PlayerMissionService.resetDailyMission(player);
//		}
//	}
//	
//	/**
//	 * 更新玩家每日重置数据
//	 * @param player
//	 */
//	public static void updatePlayerDailyData(Player player){
//		PlayerDailyData dailyData = player.getPlayerDailyData();
//		if(dailyData == null){
//			return;
//		}
//		dailyDataDao.save(dailyData);
//	}

	/**
	 * 通过openId进行登录
	 * @param openId
	 * @return
	 * @throws PatException
	 */
	public static Player login(String openId) throws PatException {
		if (openId == null || openId.equals("")) {
			throw new PatException("openId can not be empty!");
		}
		Player player = PlayerService.loadPlayerByOpenId(openId);
		//从DB加载不到玩家数据
		if (player == null) {
			return null;
		}

		player = login(player.getId());
		return player;
	}
	
	/**
	 * 通过玩家id登录
	 * @param playerId
	 * @return
	 */
	public static Player login(int playerId){
		Player player = PlayerCache.INSTANCE.getOnlinePlayer(playerId);
		if (player == null) {
			Map<Integer, Player> onlineMap = PlayerCache.INSTANCE.getOnlineMap();
			synchronized (onlineMap) {
				// 第二次判断
				Player p = PlayerCache.INSTANCE.getOnlinePlayer(playerId);
				if (p != null)
					return p;

				player = PlayerCache.INSTANCE.getPlayer(playerId, ModelData.DATA_ALL);
				
				if(player != null){
					onlineMap.put(playerId, player);
					
					//记录登录日志
					StringBuilder log = new StringBuilder();
					log.append("login|").append(player.getId()).append("|").append(player.getOpenId());
					loginLog.debug(log.toString());
				}
			}
		}
		
		//登录后处理
		loginAfter(player);
		
		return player;
	}
	
	/**
	 * 玩家登录后处理
	 * @param player
	 */
	private static void loginAfter(Player player){
		if(player == null){
			return;
		}
		
		//判断是否有新的公告
//		MessageService.resetPlayerMessage(player);
	}
	
	/**
	 * 创建玩家
	 * @param openId
	 * @param name
	 * @return
	 */
	public static Player createPlayer(String openId, String name){
		int now = TimeUtil.now();
		Player newPlayer = new Player();
		newPlayer.setId(IdGenerator.generateId(Player.class.getSimpleName()));
		newPlayer.setOpenId(openId);
		newPlayer.setName(name);
		newPlayer.setLevel(1);//TODO 测试用
		newPlayer.setExp(0);
		newPlayer.setMoney(99999);//TODO 测试用
		newPlayer.setGold(0);
		newPlayer.setSysGold(99999);//TODO 测试用
		newPlayer.setCreateTime(now);
		newPlayer.setLoginTime(now);
		newPlayer.setRoom(20); //初始负重20个格子
		newPlayer.setBattlePoint(5);
		newPlayer.setResumeTime(TimeUtil.now());
		newPlayer.setGuideStep(0);
		savePlayer(newPlayer);
		
//		//初始化玩家英雄
//		HeroService.initPlayerHero(newPlayer);
//		
//		//初始化玩家道具数据
//		ItemService.initPlayerItem(newPlayer);
//		
//		//初始化玩家每日数据
//		PlayerService.initPlayerDailyData(newPlayer);
//		
//		//初始化玩家的任务数据
//		PlayerMissionService.initPlayerMission(newPlayer);
//		
//		//初始化玩家的消息数据
//		MessageService.initPlayerMessage(newPlayer);
		
//		if(newPlayer != null){
//			//奖励更新(首次登陆奖励)
//			PlayerRewardService.updateReward(newPlayer, RewardConstant.REWARD_ID1, 1, 0);
//			PlayerRewardService.updateReward(newPlayer, RewardConstant.REWARD_ID2, 1, 0);
//			PlayerRewardService.updateReward(newPlayer, RewardConstant.REWARD_ID3, 1, 0);
//		}
		
		//记录注册日志
		StringBuilder log = new StringBuilder();
		log.append("register|").append(newPlayer.getId()).append("|").append(newPlayer.getOpenId());
		loginLog.debug(log.toString());
		
		return newPlayer;
	}

	/**
	 * 扫描在线玩家(5分钟不操作或无心跳则离线)
	 */
	public static void scan() {
		logger.info("start scan player...");
		long start = System.currentTimeMillis();
		try {
			long now = TimeUtil.now();
			Map<Integer, Player> map = PlayerCache.INSTANCE.getOnlineMap();
			
			Map<Integer, Player> newMap = new HashMap<Integer, Player>(map);
			for (Map.Entry<Integer, Player> onlineEntry : newMap.entrySet()) {
				Player player = onlineEntry.getValue();
				int accessTime = player.getAccessTime();
				if ((now - accessTime) > 20 * 60) {
					logout(player);
				}
			}
		} catch (Exception e) {
			logger.error("excecption scan player", e);
		}
		long end = System.currentTimeMillis();
		logger.info("end scan player,use time:" + (end - start));
	}

	/**
	 * 玩家登出
	 * @param player
	 */
	private static void logout(Player player) {
		PlayerCache.INSTANCE.getOnlineMap().remove(player.getId());
		
		//关闭连接通知下线
		notifyLogout(player, ErrorCode.ERR_LOGOUT_VALUE);
		
		loginLog.debug("logout|"+player.getId()+"|"+player.getOpenId());
	}
	
	/**
	 * 给玩家加经验
	 * @param player
	 * @param addExp
	 * @return
	 */
	public static int addExp(Player player, int addExp){
		if(player.getLevel() >= CommonConstant.MAX_PLAYER_LEVEL || addExp <= 0){
			return 0;
		}
	
		int realExp = 0;
		int oldExp = player.getExp();
		int oldLevel = player.getLevel();
		int newExp = oldExp + addExp;
	
//		while(true){
//			ConfigPlayerLevel configPlayerLevel = ConfigHelper.getConfigPlayerLevel(player.getLevel());
//			if(player.getLevel()< CommonConstant.MAX_PLAYER_LEVEL && configPlayerLevel.getExp() <= newExp){
//				newExp = newExp - configPlayerLevel.getExp();
//				player.setLevel(player.getLevel()+1);
//				player.setExp(0);
//			}else{
//				if(player.getLevel() >= CommonConstant.MAX_PLAYER_LEVEL){
//					newExp = 0;
//				}
//				player.setExp(newExp);
//				break;
//			}
//		}
		
		//计算实际增加的经验
//		int deltaLevel = player.getLevel() - oldLevel;
//		if(deltaLevel > 0){
//			int tmpExp = 0;
//			for(int i = oldLevel; i<player.getLevel(); i++){
//				ConfigPlayerLevel configPlayerLevel = ConfigHelper.getConfigPlayerLevel(i);
//				tmpExp += configPlayerLevel.getExp();
//			}
//			realExp = tmpExp + player.getExp() - oldExp;
//		}else{
//			realExp = player.getExp() - oldExp;
//		}
		//更新DB
		savePlayer(player);
		
		//推送玩家数据
		DataPushService.pushPlayerMsg(player);
		
		return realExp;
	}
	
	/**
	 * 添加游戏币
	 * @param player
	 * @param money
	 */
	public static void addMoney(Player player, int addMoney){
		if(addMoney == 0){
			return;
		}
		int money = player.getMoney();
		if((Integer.MAX_VALUE - money) < addMoney){
			logger.error("money exceed max value. playerId="+player.getId());
			return;
		}
		
		player.setMoney(money+addMoney);
		if(player.getMoney() < 0){
			player.setMoney(0);
		}
		
		if(player.getMoney() > CommonConstant.MAX_MONEY){
			player.setMoney(CommonConstant.MAX_MONEY);
		}
		
		//保存DB
		savePlayer(player);
		
		DataPushService.pushPlayerMsg(player);
	}
	
	/**
	 * 添加人民币
	 * @param player
	 * @param addMoney
	 * @param type 1:充值途径 2:系统产出途径
	 */
	public static void addGold(Player player, int addGold, int type){
		if(addGold == 0){
			return;
		}
		int gold = 0;
		if(type == 1){
			gold = player.getGold();
		}else if(type == 2){
			gold = player.getSysGold();
		}
		if((Integer.MAX_VALUE - gold) < addGold){
			logger.error("gold exceed max value. playerId="+player.getId());
			return;
		}
		
		if(type == 1){
			player.setGold(gold+addGold);
			if(player.getGold() < 0){
				player.setGold(0);
			}
		}else if(type == 2){
			player.setSysGold(gold+addGold);
			if(player.getSysGold() < 0){
				player.setSysGold(0);
			}
		}
		
		
		//保存DB
		savePlayer(player);
		
		DataPushService.pushPlayerMsg(player);
	}
	
//	/**
//	 * 加魂力
//	 */
//	public static void addSoul(Player player, int addSoul){
//		if(addSoul == 0){
//			return;
//		}
//		int soul = player.getSoul();
//		if((Integer.MAX_VALUE - addSoul) < soul){
//			logger.error("soul exceed max value. playerId="+player.getId());
//			return;
//		}
//		
//		player.setSoul(soul+addSoul);
//		if(player.getSoul() < 0){
//			player.setSoul(0);
//		}
//		
//		//保存DB
//		savePlayer(player);
//		
//		DataPushService.pushPlayerMsg(player);
//	}
	
	/**
	 * 检查游戏币够不够
	 * @param player
	 * @param money
	 * @return
	 */
	public static ErrorMsg checkMoney(Player player, int money){
		if(player.getMoney() < money){
			return MessageUtil.buildErrorMsg(ErrorCode.ERR_NO_MONEY_VALUE);
		}
		return null;
	}
	
	/**
	 * 检查钻石够不够
	 * @param player
	 * @param money
	 * @return
	 */
	public static ErrorMsg checkGold(Player player, int gold){
		if((player.getGold() + player.getSysGold()) < gold){
			return MessageUtil.buildErrorMsg(ErrorCode.ERR_NO_GOLD_VALUE);
		}
		return null;
	}
	
	/**
	 * 检查战斗点是否够
	 * @param player
	 * @param point
	 * @return
	 */
	public static ErrorMsg checkBattlePoint(Player player, int point){
		int battlePoint = player.getBattlePoint();
		if(battlePoint < point){
			return MessageUtil.buildErrorMsg(ErrorCode.ERR_NO_BATTLE_POINT_VALUE);
		}
		return null;
	}
	
	/**
	 * 消耗战斗点
	 * @param player
	 * @param point
	 * @return null表示无错误
	 */
	public static ErrorMsg consumeBattlePoint(Player player, int point){
		if(point <= 0){
			return MessageUtil.buildErrorMsg(ErrorCode.ERR_UNKNOWN_VALUE);
		}
		int battlePoint = player.getBattlePoint();
		if(battlePoint < point){
			return MessageUtil.buildErrorMsg(ErrorCode.ERR_NO_BATTLE_POINT_VALUE);
		}
		
		
		if(player.getBattlePoint() == CommonConstant.FULL_BATTLE_POINT){
			player.setResumeTime(TimeUtil.now());
		}
		
		player.setBattlePoint(battlePoint - point);
		
		//保存到DB
		savePlayer(player);
		
		//推送人物数据
		DataPushService.pushPlayerMsg(player);
		
		return null;
	}
	
	/**
	 * 消耗游戏币
	 * @param player
	 * @param money
	 */
	public static void consumeMoney(Player player, int money){
		if(player.getMoney() < money){
			logger.error("cost_money|error|"+player.getId()+"|"+player.getMoney()+"|"+money);
			throw new RuntimeException("consumet money error");
		}
		if(money == 0){
			return;
		}
		
		player.setMoney(player.getMoney() - money);
		
		//保存到DB
		savePlayer(player);
		
		//推送人物数据
		DataPushService.pushPlayerMsg(player);
	}
	
	/**
	 * 消耗人民币(先从玩家充值的金额中扣除然后再从系统产出中扣除)
	 * @param player
	 * @param gold
	 */
	public static void consumeGold(Player player, int gold){
		int totalGold = player.getGold() + player.getSysGold();
		if(totalGold < gold){
			logger.error("cost_gold|error|"+player.getId()+"|"+player.getGold()+"|"+player.getSysGold()+"|"+gold);
			throw new RuntimeException("consumet gold error");
		}
		
		if(gold == 0){
			return;
		}
		
		int remain = player.getGold() - gold;
		if(remain >= 0){
			player.setGold(remain);
		}else{
			player.setSysGold(player.getSysGold() + remain);
			player.setGold(0);
		}
		
		
		//保存到DB
		savePlayer(player);
		
		//推送人物数据
		DataPushService.pushPlayerMsg(player);
	}
	
//	/**
//	 * 消费魂力
//	 * @param player
//	 * @param soul
//	 */
//	public static void consumeSoul(Player player, int soul){
//		if(player.getSoul() < soul){
//			logger.error("cost_soul|error|"+player.getId()+"|"+player.getSoul()+"|"+soul);
//			throw new RuntimeException("consumet soul error");
//		}
//		
//		if(soul == 0){
//			return;
//		}
//		
//		player.setSoul(player.getSoul() - soul);
//		
//		//保存到DB
//		savePlayer(player);
//		
//		//推送人物数据
//		DataPushService.pushPlayerMsg(player);
//	}
	
	/**
	 * 增加初始出战英雄数量
	 * @param player
	 */
	public static void addFightHeroNum(Player player){
		int num = player.getMaxFightHeroNum();
		int needGold = 0;
		int needMoney = 0;
		switch (num) {
			case 1:
				needMoney = 5000;
				break;
			case 2:
				needMoney = 35000;
				break;
			case 3:
				needGold = 500;
				break;
		}
		if(needGold > 0){
			//扣人民币
			consumeGold(player, needGold);
		}
		if(needMoney > 0){
			consumeMoney(player, needMoney);
		}
		
		player.setMaxFightHeroNum(player.getMaxFightHeroNum() + 1);
		
		savePlayer(player);
		
		DataPushService.pushPlayerMsg(player);
	}
	
	/**
	 * 系统恢复战斗点
	 * @param player
	 */
	public static void resumeBattlePoint(Player player){
		//检查战斗点恢复
		int resumeTime = player.getResumeTime();
		int deltaTime = TimeUtil.now() - resumeTime;//间隔时间
		int value = deltaTime / CommonConstant.RESUME_DELTA_TIME;
		if(value > 0 && player.getBattlePoint() < CommonConstant.FULL_BATTLE_POINT){
			player.setBattlePoint(player.getBattlePoint() + value);
			if(player.getBattlePoint() > CommonConstant.FULL_BATTLE_POINT){
				player.setBattlePoint(CommonConstant.FULL_BATTLE_POINT);
			}
			player.setResumeTime(resumeTime + value * CommonConstant.RESUME_DELTA_TIME);
			
			savePlayer(player);
			
			DataPushService.pushPlayerMsg(player);
		}
	}
	
	/**
	 * 增加战斗点
	 * @param player
	 * @param point
	 */
	public static void addBattlePoint(Player player, int point){
		if(point == 0){
			return;
		}
		int battlePoint = player.getBattlePoint();
		if((battlePoint + point) > (CommonConstant.FULL_BATTLE_POINT + CommonConstant.MAX_STORE_BATTLE_POINT)){
			logger.error("battle point exceed max value. playerId="+player.getId());
			return;
		}
		
		player.setBattlePoint(battlePoint+point);
		if(player.getBattlePoint() < 0){
			player.setBattlePoint(0);
		}
		
		//保存DB
		savePlayer(player);
		
		DataPushService.pushPlayerMsg(player);
	}
	
	/**
	 * 通知玩家下线
	 * @param player
	 */
	public static void notifyLogout(Player player, int errCode){
		Channel channel = player.getChannel();
		PBMessage.Builder body = MessageUtil.buildMessage(player.getId(), 0);
		ErrorMsg errMsg = MessageUtil.buildErrorMsg(errCode);
		body.setErrorCode(errCode);
		body.setData(errMsg.toByteString());
		ChannelFuture future = NettyUtil.sendMessage2Client(channel, body.build());
		if(future != null){
			future.addListener(ChannelFutureListener.CLOSE);
		}
	}
	
	/**
	 * 获得购买游戏币的数量
	 * @param costGold
	 * @return
	 */
	public static int getBuyMoneyAmount(int costGold){
		int money = 0;
		switch (costGold) {
			case 100:
				money = 20000;
				break;
			case 245:
				money = 50000;	
				break;
			case 580:
				money = 120000;
				break;
			case 1200:
				money = 250000;
				break;
		}
		return money;
	}
	
	/**
	 * 购买游戏币
	 * @param player
	 * @param costGold 消耗的钻石
	 */
	public static void buyMoney(Player player, int costGold){
		int money = getBuyMoneyAmount(costGold);
		
		//消耗钻石
		PlayerService.consumeGold(player, costGold);
		
		//加游戏币
		PlayerService.addMoney(player, money);
	}
	
	/**
	 * 获得购买战斗点的数量
	 * @param costGold
	 * @return
	 */
	public static int getBuyBattlePointAmount(int costGold){
		int battlePoint = 0;
		switch (costGold) {
			case 25:
				battlePoint = 10;
				break;
			case 60:
				battlePoint = 25;	
				break;
			case 120:
				battlePoint = 50;
				break;
			case 230:
				battlePoint = 100;
				break;
		}
		return battlePoint;
	}
	
	/**
	 * 购买战斗点
	 * @param player
	 * @param costGold 消耗的钻石
	 */
	public static void buyBattlePoint(Player player, int costGold){
		int point = getBuyBattlePointAmount(costGold);
		
		//消耗钻石
		PlayerService.consumeGold(player, costGold);
		
		//加战斗点
		PlayerService.addBattlePoint(player, point);
	}
	
//	/**
//	 * 初始化每日数据
//	 * @param player
//	 */
//	public static void initPlayerDailyData(Player player){
//		PlayerDailyData playerDailyData = new PlayerDailyData();
//		playerDailyData.setId(player.getId());
//		playerDailyData.setResetTime(0);
//		//保存进DB
//		dailyDataDao.save(playerDailyData);
//		player.addDataLoadSign(ModelData.DATA_DAILY_DATA);
//		player.setPlayerDailyData(playerDailyData);
//		
//		resetPlayerDailyData(player);
//	}
	
//	/**
//	 * 增加扭蛋次数
//	 * @param player
//	 * @param delta 可以为负数
//	 */
//	public static void addHeroLotteryTimes(Player player, int delta){
//		int times = player.getHeroLotteryTimes();
//		int nextTimes = times + delta;
//		if(nextTimes > 20){
//			nextTimes = 20;
//		}
//		if(nextTimes < 0){
//			nextTimes = 0;
//		}
//		
//		if(nextTimes != times){
//			player.setHeroLotteryTimes(nextTimes);
//			savePlayer(player);
//			DataPushService.pushPlayerMsg(player);
//		}
//	}
	
//	/**
//	 * 获取奖励
//	 * @param player
//	 * @param configReward
//	 * @return
//	 */
//	public static BonusMsg.Builder recieveReward(Player player, ConfigReward configReward){
//		BonusMsg.Builder result = BonusMsg.newBuilder();
//		result.setBattlePoint(0);
//		result.setExp(0);
//		result.setGold(0);
//		result.setMoney(0);
//		result.setExp(0);
//		//添加奖励
//		if(configReward == null){
//			return result;
//		}
//		if(configReward.getBonusBattlePoint() > 0){
//			PlayerService.addBattlePoint(player, configReward.getBonusBattlePoint());
//			result.setBattlePoint(configReward.getBonusBattlePoint());
//		}
//		if(configReward.getBonusMoney() > 0){
//			PlayerService.addMoney(player, configReward.getBonusMoney());
//			result.setMoney(configReward.getBonusMoney());
//		}
//		if(configReward.getBonusGold() > 0){
//			PlayerService.addGold(player, configReward.getBonusGold(), 2);
//			result.setGold(configReward.getBonusGold());
//		}
//		if(configReward.getBonusExp() > 0){
//			int realExp = PlayerService.addExp(player, configReward.getBonusExp());
//			result.setExp(realExp);
//		}
//		if(configReward.getBonusItem() != null && !configReward.getBonusItem().trim().equals("")){
//			String[] strBonusItems = configReward.getBonusItem().split("[,]");
//			for(String strBonusItem : strBonusItems){
//				String[] strItem = strBonusItem.split("[_]");
//				int realAmount = ItemService.addItem(player, Integer.valueOf(strItem[0]), Integer.valueOf(strItem[1]));
//				if(realAmount > 0){
//					SimpleItemMsg.Builder itemMsg = SimpleItemMsg.newBuilder();
//					itemMsg.setAmount(realAmount);
//					itemMsg.setItemId(Integer.valueOf(strItem[0]));
//					result.addItem(itemMsg);
//				}
//			}
//		}
//		
//		return result;
//	}
//	
//	/**
//	 * 将src中的奖励信息合并到result中
//	 * @param result
//	 * @param src
//	 */
//	public static void mergeBonus(BonusMsg.Builder result, BonusMsg src){
//		result.setBattlePoint(result.getBattlePoint() + src.getBattlePoint());
//		result.setGold(result.getGold() + src.getGold());
//		result.setMoney(result.getMoney() + src.getMoney());
//		result.setExp(result.getExp() + src.getExp());
//		result.setHeroId(src.getHeroId());
//		result.addAllItem(src.getItemList());
//	}
	
	/**
	 * 更新新手引导步骤
	 * @param player
	 * @param step
	 */
	public static void updateGuideStep(Player player, int step){
		player.setGuideStep(step);
		savePlayer(player);
		
		DataPushService.pushPlayerMsg(player);
	}
	
	/**
	 * 更新玩家等级(管理接口修改玩家等级)
	 * @param player
	 * @param level
	 */
	public static void updatePlayerLevel(Player player, int level){
		player.setLevel(level);
		savePlayer(player);
		
		DataPushService.pushPlayerMsg(player);
	}
}
